package com.itheima.controller;

import com.itheima.domain.Patients;
import com.itheima.service.PatientsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author zhengjd
 * @date 2020/3/24 20:06
 */
@Controller
@RequestMapping("/product")
public class PatientsController {

    @Autowired
    PatientsService patientsService;

    /**
     * 添加挂号信息
     * @param patients
     * @return
     */
    @RequestMapping("/save")
    public String save(Patients patients){
        int rows = patientsService.save(patients);
        return "redirect:/pages/subscribe-form.jsp";
    }

    /**
     * 查询所有患者信息
     * @return
     */

    @RequestMapping("/findAll")
    public String  findAll(Model model){
        List<Patients> patients = patientsService.findAll();
        model.addAttribute("list",patients);
        return "/pages/patients-list.jsp";
    }

    /**
     * 查询指定患者信息
     * @return
     */

    @RequestMapping("/findById")
    public String findById(Integer id,Model model){
       Patients patients =  patientsService.findById(id);
       model.addAttribute("patient",patients);
        return "/pages/subscribe-form-update.jsp";
    }

    /**
     * 更新患者信息
     */
    @RequestMapping("/update")
    public String update(Patients patients){
        patientsService.update(patients);
        return "redirect:/product/findAll";
    }
}
